<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Cache-Control" content="no-siteapp" />

    <title>Create and upload C/C++ packages to xmake&#39;s official repository</title>
    <meta name="description" content="Xmake integrates built-in remote package dependency management. Users simply add the packages and versions they need to the project, and then automatically d...">

    
    <meta name="keywords" content="xmake,lua,C/C++,package,repository,tboox" /> 

    <!-- qq oauth -->
    <meta property="qc:admins" content="5211601217706727767255" />

    <!--icon -->
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" sizes="192x192" href="/static/img/nice-highres.png" />
	<link rel="apple-touch-icon-precomposed" href="/static/img/apple-touch-icon-57x57-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/img/apple-touch-icon-72x72-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/img/apple-touch-icon-114x114-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/img/apple-touch-icon-144x144-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="180x180" href="/static/img/retinahd_icon.png" />
	<meta name="msapplication-TileImage" content="/static/img/retinahd_icon.png" />
	
    <link rel="stylesheet" href=" /css/fontawesome/css/font-awesome.min.css ">
    <link rel="stylesheet" href=" /css/main.css ">
    <link rel="canonical" href="https://tboox.org/2019/08/09/xmake-upload-package/">
    <link rel="alternate" type="application/rss+xml" title="TBOOX Open Source Project" href="https://tboox.org/feed.xml ">
    <link rel="alternate" hreflang="en" href="https://tboox.org/" />
    <link rel="alternate" hreflang="zh-Hans" href="https://tboox.org/cn/" />




    <script type="text/javascript">
    function isPC(){    
        var userAgentInfo = navigator.userAgent;  
        var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");    
        var flag = true;    
        for (var v = 0; v < Agents.length; v++) {    
            if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }    
        }    
        return flag;    
    }
    </script>

<!-- baidu ads -->



    <!-- baidu ads -->

</head>


  <body>

    <header id="top">
    <div class="wrapper">
        <a href="/" class="brand">TBOOX</a>
        <button id="headerMenu" class="menu"><i class="fa fa-bars"></i></button>
        <nav id="headerNav">
            <ul>
                <li>
                    
                    <a href="/cn?lang=0">
                    
                        <i class="fa fa-home"></i>中文
                    </a>
                </li>

                
                    
                     
                    
                
                    
                     
                     
                    <li>

                        
                            
                            <a href="/project/">
                            
                        
                            <i class="fa fa-bookmark"></i>Projects
                        </a>
                    </li>
                    
                    
                    
                
                    
                     
                    
                
                    
                     
                     
                    <li>

                        
                            
                            <a href="/archive/">
                            
                        
                            <i class="fa fa-archive"></i>Archives
                        </a>
                    </li>
                    
                    
                    
                
                    
                     
                    
                
                    
                     
                     
                    <li>

                        
                            
                            <a href="/category/">
                            
                        
                            <i class="fa fa-th-list"></i>Categories
                        </a>
                    </li>
                    
                    
                    
                
                    
                     
                    
                
                    
                     
                     
                    <li>

                        
                            
                            <a href="/tag/">
                            
                        
                            <i class="fa fa-tags"></i>Tags
                        </a>
                    </li>
                    
                    
                    
                
                    
                
                    
                     
                    
                
                    
                     
                     
                    <li>

                        
                            
                            <a href="/docs/">
                            
                        
                            <i class="fa fa-book"></i>Documents
                        </a>
                    </li>
                    
                    
                    
                
                    
                     
                    
                
                    
                     
                     
                    <li>

                        
                            
                            <a href="https://xmake.io/#/about/contact" target="_blank" >
                            
                        
                            <i class="fa fa-forumbee"></i>Community
                        </a>
                    </li>
                    
                    
                    
                
                    
                     
                    
                
                    
                     
                     
                    <li>

                        
                            
                            <a href="/donation/">
                            
                        
                            <i class="fa fa-heart"></i>Donate
                        </a>
                    </li>
                    
                    
                    
                
                    
                     
                    
                
                    
                     
                     
                    <li>

                        
                            
                            <a href="/about/">
                            
                        
                            <i class="fa fa-user"></i>About
                        </a>
                    </li>
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                     
                     
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            </ul>
        </nav>
    </div>
</header>



        <div class="page clearfix" post>
    <div class="left">
        <h1>Create and upload C/C++ packages to xmake's official repository</h1>
        <div class="label">

            <div class="label-card">
                <i class="fa fa-calendar"></i>2019-08-09
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
            


<!-- <span class="point">•</span> -->
<span class="categories">
  <i class="fa fa-th-list"></i>
  
    
        <a href="/category/#xmake" title="Category: xmake" rel="category">xmake</a>
    
  

  <!-- <span class="point">•</span> -->
</span>


            </div>

            <div class="label-card">
            
<!-- <span class="point">•</span> -->
<span class="pageTag">
  <i class="fa fa-tags"></i>
  
    
        <!--a href="/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a-->
        <a href="/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a>&nbsp;
    
        <!--a href="/tag/#lua" title="Tag: lua" rel="tag">lua</a-->
        <a href="/tag/#lua" title="Tag: lua" rel="tag">lua</a>&nbsp;
    
        <!--a href="/tag/#C%2FC%2B%2B" title="Tag: C/C++" rel="tag">C/C++</a-->
        <a href="/tag/#C/C++" title="Tag: C/C++" rel="tag">C/C++</a>&nbsp;
    
        <!--a href="/tag/#package" title="Tag: package" rel="tag">package</a-->
        <a href="/tag/#package" title="Tag: package" rel="tag">package</a>&nbsp;
    
        <!--a href="/tag/#repository" title="Tag: repository" rel="tag">repository</a-->
        <a href="/tag/#repository" title="Tag: repository" rel="tag">repository</a>
    
  

</span>

            </div>

        </div>
        <hr>
        <article itemscope itemtype="http://schema.org/BlogPosting">
        <p>Xmake integrates built-in remote package dependency management. Users simply add the packages and versions they need to the project, and then automatically download and integrate the corresponding packages into the project, and compile and link.</p>

<p>For example:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"libuv master"</span><span class="p">,</span> <span class="s2">"ffmpeg"</span><span class="p">,</span> <span class="s2">"zlib 1.20.*"</span><span class="p">)</span>
<span class="n">add_requires</span><span class="p">(</span><span class="s2">"tbox &gt;1.6.1"</span><span class="p">,</span> <span class="p">{</span><span class="n">optional</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span> <span class="n">debug</span> <span class="o">=</span> <span class="kc">true</span><span class="p">})</span>
<span class="n">add_requires</span><span class="p">(</span><span class="s2">"boost"</span><span class="p">,</span> <span class="p">{</span><span class="n">alias</span> <span class="o">=</span> <span class="s2">"boost_context"</span><span class="p">,</span> <span class="n">configs</span> <span class="o">=</span> <span class="p">{</span><span class="n">context</span> <span class="o">=</span> <span class="kc">true</span><span class="p">}})</span>
<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
<span class="err">    </span><span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
<span class="err">    </span><span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
<span class="err">    </span><span class="n">add_packages</span><span class="p">(</span><span class="s2">"libuv"</span><span class="p">,</span> <span class="s2">"ffmpeg"</span><span class="p">,</span> <span class="s2">"tbox"</span><span class="p">,</span> <span class="s2">"boost_context"</span><span class="p">,</span> <span class="s2">"zlib"</span><span class="p">)</span>
</code></pre>
</div>

<p>Xmake’s package repository was designed with semantic version support and cross-platform support for dependencies. As long as the package itself supports the platform, it can be integrated, such as zlib package, used in xmake, iphoneos, android and mingw. All platforms are fully available.</p>

<p>Users only need to simply cut the build platform:</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code>xmake f -p iphoneos -a arm64
xmake
note: try installing these packages <span class="o">(</span>pass -y to skip confirm<span class="o">)</span>?
<span class="k">in </span>xmake-repo:
<span class="gp">  -&gt; </span>zlib 1.2.11
please input: y <span class="o">(</span>y/n<span class="o">)</span>
<span class="gp">  =&gt; </span>download https://downloads.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz .. ok
<span class="gp">  =&gt; </span>install zlib 1.2.11 .. ok
</code></pre>
</div>

<p>You can download the corresponding package in the ‘add_requires` for the iphoneos platform. The ultimate goal of xmake is to create a cross-platform package repository. Users no longer need to find the c/c++ library, and then study the migration of various platforms. You need to simply add the package dependencies, which can be easily used on all platforms.</p>

<p>Of course, the current xmake official warehouse is still in the early stage of development, there are still few packages, and the supported platforms are not perfect. Therefore, here I briefly introduce how users can make and upload their own c/c++ packages. And how to submit it to our warehouse (you can also build your own private warehouse),
I hope that interested partners can help to contribute a small amount of effort to jointly build and build a c/c++ dependency package ecosystem.</p>

<ul>
  <li><a href="https://github.com/xmake-io/xmake">project source</a></li>
  <li><a href="https://xmake.io/#/en/">Official Document</a></li>
</ul>

<h2 id="adding-packages-to-the-official-repository">Adding packages to the official repository</h2>

<h3 id="package-structure-in-repository">Package structure in repository</h3>

<p>Before making our own package, we need to understand the structure of the next package repository, whether it is the official package repository or the self-built private package repository, the structure is the same:</p>

<div class="highlighter-rouge"><pre class="highlight"><code>xmake-repo
   - packages
     - t/tbox/xmake.lua
     - z/zlib/xmake.lua
</code></pre>
</div>

<p>Through the above structure, you can see that each package will have a xmake.lua to describe its installation rules, and according to the <code class="highlighter-rouge">z/zlib</code> two-level sub-category storage, convenient for quick retrieval.</p>

<h3 id="package-description">Package Description</h3>

<p>The description rules for the package are basically done in its xmake.lua, which is similar to the xmake.lua description in the project project. The difference is that the description field only supports <code class="highlighter-rouge">package()</code>.</p>

<p>However, in the project xmake.lua, you can also directly add <code class="highlighter-rouge">package()</code> to the built-in package description, and even the package warehouse is saved, sometimes it will be more convenient.</p>

<p>First, let’s take a look at zlib’s description rules first. This rule can be found at <a href="https://github.com/xmake-io/xmake-repo/blob Found under /master/packages/z/zlib/xmake.lua">xmake-repo/z/zlib/xmake.lua</a>.</p>

<div class="highlighter-rouge"><pre class="highlight"><code>package("zlib")

    set_homepage("http://www.zlib.net")
    set_description("A Massively Spiffy Yet Delicately Unobtrusive Compression Library")

    set_urls("http://zlib.net/zlib-$(version).tar.gz",
             "https://downloads.sourceforge.net/project/libpng/zlib/$(version)/zlib-$(version).tar.gz")

    add_versions("1.2.10", "8d7e9f698ce48787b6e1c67e6bff79e487303e66077e25cb9784ac8835978017")
    add_versions("1.2.11", "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1")

    on_install("windows", function (package)
        io.gsub("win32/Makefile.msc", "%-MD", "-" .. package:config("vs_runtime"))
        os.vrun("nmake -f win32\\Makefile.msc zlib.lib")
        os.cp("zlib.lib", package:installdir("lib"))
        os.cp("*.h", package:installdir("include"))
    end)

    on_install("linux", "macosx", function (package)
        import("package.tools.autoconf").install(package, {"--static"})
    end)
 
    on_install("iphoneos", "android@linux,macosx", "mingw@linux,macosx", function (package)
        import("package.tools.autoconf").configure(package, {host = "", "--static"})
        io.gsub("Makefile", "\nAR=.-\n",      "\nAR=" .. (package:build_getenv("ar") or "") .. "\n")
        io.gsub("Makefile", "\nARFLAGS=.-\n", "\nARFLAGS=cr\n")
        io.gsub("Makefile", "\nRANLIB=.-\n",  "\nRANLIB=\n")
        os.vrun("make install -j4")
    end)

    on_test(function (package)
        assert(package:has_cfuncs("inflate", {includes = "zlib.h"}))
    end)
</code></pre>
</div>

<p>This package rule adds installation rules to windows, linux, macosx, iphoneos, mingw and other platforms. Basically, it has achieved full platform coverage, and even some cross-compilation platforms, which is a typical example.</p>

<p>Of course, some packages rely on source code implementation and are not completely cross-platform, so you only need to set the installation rules for the platforms it supports.</p>

<h4 id="set_homepage">set_homepage</h4>

<p>Set the official page address of the project where the package is located.</p>

<h4 id="set_description">set_description</h4>

<p>Set the package description information, generally see the relevant package information through <code class="highlighter-rouge">xmake require --info zlib</code>.</p>

<h4 id="set_kind">set_kind</h4>

<p>Set the package type. For the dependent library, you don’t need to set it. If it is an executable package, you need to set it to binary.</p>

<div class="highlighter-rouge"><pre class="highlight"><code>package("cmake")

    set_kind("binary")
    set_homepage("https://cmake.org")
    set_description("A cross-platform family of tool designed to build, test and package software")
</code></pre>
</div>

<h4 id="set_urls">set_urls</h4>

<p>Set the source package or git repository address of the package. Unlike add_urls, this interface is the override setting, and add_urls is the additional setting. Other usage methods are similar. This is chosen according to different needs.</p>

<h4 id="add_urls">add_urls</h4>

<p>Add the source package of the package or the git repository address. This interface is generally paired with add_version to set the version of each source package and the corresponding sha256 value.</p>

<p>!&gt; You can add multiple urls as the mirror source, xmake will automatically detect the fastest url for download, and if the download fails, try other urls.</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_urls</span><span class="p">(</span><span class="s2">"https://github.com/protobuf-c/protobuf-c/releases/download/v$(version)/protobuf-c-$(version).tar.gz"</span><span class="p">)</span>
<span class="n">add_versions</span><span class="p">(</span><span class="s2">"1.3.1"</span><span class="p">,</span> <span class="s2">"51472d3a191d6d7b425e32b612e477c06f73fe23e07f6a6a839b11808e9d2267"</span><span class="p">)</span>
</code></pre>
</div>

<p>The <code class="highlighter-rouge">$(version)</code> built-in variable in urls will be adapted according to the version selected during the actual installation, and the version number is selected from the list of versions specified in <code class="highlighter-rouge">add_versions</code>.</p>

<p>If there is a more complicated version string for urls and there is no direct correspondence with add_versions, you need to customize the conversion in the following way:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_urls</span><span class="p">(</span><span class="s2">"https://sqlite.org/2018/sqlite-autoconf-$(version)000.tar.gz"</span><span class="p">,</span>
         <span class="p">{</span><span class="n">version</span> <span class="o">=</span> <span class="k">function</span> <span class="p">(</span><span class="n">version</span><span class="p">)</span> <span class="k">return</span> <span class="n">version</span><span class="p">:</span><span class="n">gsub</span><span class="p">(</span><span class="s2">"%."</span><span class="p">,</span> <span class="s2">""</span><span class="p">)</span> <span class="k">end</span><span class="p">})</span>

<span class="n">add_versions</span><span class="p">(</span><span class="s2">"3.24.0"</span><span class="p">,</span> <span class="s2">"d9d14e88c6fb6d68de9ca0d1f9797477d82fc3aed613558f87ffbdbbc5ceb74a"</span><span class="p">)</span>
<span class="n">add_versions</span><span class="p">(</span><span class="s2">"3.23.0"</span><span class="p">,</span> <span class="s2">"b7711a1800a071674c2bf76898ae8584fc6c9643cfe933cfc1bc54361e3a6e49"</span><span class="p">)</span>
</code></pre>
</div>

<p>Of course, we can only add the git source address:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_urls</span><span class="p">(</span><span class="s2">"https://gitlab.gnome.org/GNOME/libxml2.git"</span><span class="p">)</span>
</code></pre>
</div>

<p>If the source code package sha256 corresponding to multiple mirror addresses is different, we can set them separately by means of alias:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_urls</span><span class="p">(</span><span class="s2">"https://ffmpeg.org/releases/ffmpeg-$(version).tar.bz2"</span><span class="p">,</span> <span class="p">{</span><span class="n">alias</span> <span class="o">=</span> <span class="s2">"home"</span><span class="p">})</span>
<span class="n">add_urls</span><span class="p">(</span><span class="s2">"https://github.com/FFmpeg/FFmpeg/archive/n$(version).zip"</span><span class="p">,</span> <span class="p">{</span><span class="n">alias</span> <span class="o">=</span> <span class="s2">"github"</span><span class="p">})</span>
<span class="n">add_versions</span><span class="p">(</span><span class="s2">"home:4.0.2"</span><span class="p">,</span> <span class="s2">"346c51735f42c37e0712e0b3d2f6476c86ac15863e4445d9e823fe396420d056"</span><span class="p">)</span>
<span class="n">add_versions</span><span class="p">(</span><span class="s2">"github:4.0.2"</span><span class="p">,</span> <span class="s2">"4df1ef0bf73b7148caea1270539ef7bd06607e0ea8aa2fbf1bb34062a097f026"</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="add_versions">add_versions</h4>

<p>Used to set the version of each source package and the corresponding sha256 value, as described in <a href="https://xmake.io/#/package/remote_package?id=add_urls">add_urls</a></p>

<h4 id="add_patches">add_patches</h4>

<p>This interface is used for the source code package. Before compiling and installing, firstly set the corresponding patch package, compile it, and support multiple patches at the same time.</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="k">if</span> <span class="n">is_plat</span><span class="p">(</span><span class="s2">"macosx"</span><span class="p">)</span> <span class="k">then</span>
<span class="err">    </span><span class="n">add_patches</span><span class="p">(</span><span class="s2">"1.15"</span><span class="p">,</span> <span class="s2">"https://raw.githubusercontent.com/Homebrew/patches/9be2793af/libiconv/patch-utf8mac.diff"</span><span class="p">,</span>
<span class="err">                        </span><span class="s2">"e8128732f22f63b5c656659786d2cf76f1450008f36bcf541285268c66cabeab"</span><span class="p">)</span>
<span class="k">end</span>
</code></pre>
</div>

<p>For example, the above code, when compiled for macosx, is marked with the corresponding patch-utf8mac.diff patch, and each patch is also set to the value of sha256 to ensure integrity.</p>

<h4 id="add_links">add_links</h4>

<p>By default, xmake will automatically detect the installed libraries and set the link relationship, but sometimes it is not very accurate. If you want to manually adjust the link order and the link name, you can set it through this interface.</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_links</span><span class="p">(</span><span class="s2">"mbedtls"</span><span class="p">,</span> <span class="s2">"mbedx509"</span><span class="p">,</span> <span class="s2">"mbedcrypto"</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="add_syslinks">add_syslinks</h4>

<p>Add some system library links. When some packages integrate links, you also need to rely on some system libraries to link them. This time you can attach them to the package description.</p>

<div class="highlighter-rouge"><pre class="highlight"><code>if is_plat("macosx") then
    add_frameworks("CoreGraphics", "CoreFoundation", "Foundation")
elseif is_plat("windows") then
    add_defines("CAIRO_WIN32_STATIC_BUILD=1")
    add_syslinks("gdi32", "msimg32", "user32")
else
    add_syslinks("pthread")
end
</code></pre>
</div>

<h4 id="add_frameworks">add_frameworks</h4>

<p>Add a dependent system frameworks link.</p>

<p>See for example: <a href="https://xmake.io/#/package/remote_package?id=add_syslinks">add_syslinks</a></p>

<h4 id="add_linkdirs">add_linkdirs</h4>

<p>The package’s link library search directory can also be adjusted, but it is usually not needed, unless some libraries are not installed under prefix/lib, but in the lib subdirectory, the default search is not available.</p>

<h4 id="add_includedirs">add_includedirs</h4>

<p>Add another header file search directory.</p>

<h4 id="add_defines">add_defines</h4>

<p>Some specific definition options can be exported to the integrated package.</p>

<h4 id="add_configs">add_configs</h4>

<p>We can add the external output configuration parameters of each package through this interface:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">package</span><span class="p">(</span><span class="s2">"pcre2"</span><span class="p">)</span>

    <span class="n">set_homepage</span><span class="p">(</span><span class="s2">"https://www.pcre.org/"</span><span class="p">)</span>
    <span class="n">set_description</span><span class="p">(</span><span class="s2">"A Perl Compatible Regular Expressions Library"</span><span class="p">)</span>

    <span class="n">add_configs</span><span class="p">(</span><span class="s2">"bitwidth"</span><span class="p">,</span> <span class="p">{</span><span class="n">description</span> <span class="o">=</span> <span class="s2">"Set the code unit width."</span><span class="p">,</span> <span class="n">default</span> <span class="o">=</span> <span class="s2">"8"</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"8"</span><span class="p">,</span> <span class="s2">"16"</span><span class="p">,</span> <span class="s2">"32"</span><span class="p">}})</span>

    <span class="n">on_load</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
        <span class="kd">local</span> <span class="n">bitwidth</span> <span class="o">=</span> <span class="n">package</span><span class="p">:</span><span class="n">config</span><span class="p">(</span><span class="s2">"bitwidth"</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">"8"</span>
        <span class="n">package</span><span class="p">:</span><span class="n">add</span><span class="p">(</span><span class="s2">"links"</span><span class="p">,</span> <span class="s2">"pcre2-"</span> <span class="o">..</span> <span class="n">bitwidth</span><span class="p">)</span>
        <span class="n">package</span><span class="p">:</span><span class="n">add</span><span class="p">(</span><span class="s2">"defines"</span><span class="p">,</span> <span class="s2">"PCRE2_CODE_UNIT_WIDTH="</span> <span class="o">..</span> <span class="n">bitwidth</span><span class="p">)</span>
    <span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>In the engineering project, we can also view a list of configurable parameters and values for a particular package:</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake require --info pcre2
The package info of project:
    require<span class="o">(</span>pcre2<span class="o">)</span>: 
      -&gt; description: A Perl Compatible Regular Expressions Library
      -&gt; version: 10.31
      ...
      -&gt; configs:
         -&gt; bitwidth:
            -&gt; description: Set the code unit width.
            -&gt; values: <span class="o">{</span><span class="s2">"8"</span>,<span class="s2">"16"</span>,<span class="s2">"32"</span><span class="o">}</span>
            -&gt; default: 8
</code></pre>
</div>

<p>Then in the project, enable these configurations and compile the package with the specific configuration:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"pcre2"</span><span class="p">,</span> <span class="p">{</span><span class="n">configs</span> <span class="o">=</span> <span class="p">{</span><span class="n">bitwidth</span> <span class="o">=</span> <span class="mi">16</span><span class="p">}})</span>
</code></pre>
</div>

<h4 id="on_load">on_load</h4>

<p>This is an optional interface. If you want to be more flexible and dynamically judge various platform architectures, you can do it in this way, for example:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_load</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="n">Local</span> <span class="n">bitwidth</span> <span class="o">=</span> <span class="n">package</span><span class="p">:</span><span class="n">config</span><span class="p">(</span><span class="s2">"bitwidth"</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">"8"</span>
<span class="err">    </span><span class="n">package</span><span class="p">:</span><span class="n">add</span><span class="p">(</span><span class="s2">"links"</span><span class="p">,</span> <span class="s2">"pcre"</span> <span class="o">..</span> <span class="p">(</span><span class="n">bitwidth</span> <span class="o">~=</span> <span class="s2">"8"</span> <span class="ow">and</span> <span class="n">bitwidth</span> <span class="ow">or</span> <span class="s2">""</span><span class="p">))</span>
<span class="err">    </span><span class="n">If</span> <span class="ow">not</span> <span class="n">package</span><span class="p">:</span><span class="n">config</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span> <span class="k">then</span>
<span class="err">        </span><span class="n">package</span><span class="p">:</span><span class="n">add</span><span class="p">(</span><span class="s2">"defines"</span><span class="p">,</span> <span class="s2">"PCRE_STATIC"</span><span class="p">)</span>
<span class="err">    </span><span class="k">end</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>The pcre package needs to do some judgment on the bitwidth to determine the name of the link library for external output. It also needs to add some defines to the dynamic library. This time, it is more flexible when set in on_load.</p>

<h4 id="on_install">on_install</h4>

<p>This interface is mainly used to add installation scripts. The preceding string parameters are used to set up supported platforms. Other script fields like <code class="highlighter-rouge">on_load</code>, <code class="highlighter-rouge">on_test</code> are also supported.</p>

<h5 id="platform-filtering">Platform Filtering</h5>

<p>The complete filtering syntax is as follows: <code class="highlighter-rouge">plat|arch1,arch2@host|arch1,arch2</code></p>

<table>
  <tbody>
    <tr>
      <td>It looks very complicated, but it is very simple. Each stage is optional and can be partially omitted. Corresponding: `Compile Platform</td>
      <td>Compile Architecture@Host Platform</td>
      <td>Host Architecture</td>
    </tr>
  </tbody>
</table>

<p>If you do not set any platform filtering conditions, then the default full platform support, the script inside is effective for all platforms, for example:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_install</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="c1">-- TODO</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>If the installation script is valid for a specific platform, then directly specify the corresponding compilation platform, you can specify more than one at the same time:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_install</span><span class="p">(</span><span class="s2">"linux"</span><span class="p">,</span> <span class="s2">"macosx"</span><span class="p">,</span> <span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="c1">-- TODO</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>If you want to break down to the specified architecture to take effect, you can write:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_install</span><span class="p">(</span><span class="s2">"linux|x86_64"</span><span class="p">,</span> <span class="s2">"iphoneos|arm64"</span><span class="p">,</span> <span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="c1">-- TODO</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>If you want to limit the execution of the host environment platform and architecture, you can append <code class="highlighter-rouge">@host|arch</code> to the end, for example:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_install</span><span class="p">(</span><span class="s2">"mingw@windows"</span><span class="p">,</span> <span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="c1">-- TODO</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>This means that only the mingw platform is valid for Windows.</p>

<p>We can also specify the host platform and architecture without specifying a platform and architecture. This is usually used to describe some dependencies related to the build tool and can only be run in the host environment.</p>

<p>For example, the package we compiled depends on cmake, we need to add the package description of cmake, then the compiler installation environment can only be the host platform:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_install</span><span class="p">(</span><span class="s2">"@windows"</span><span class="p">,</span> <span class="s2">"@linux"</span><span class="p">,</span> <span class="s2">"@macosx"</span><span class="p">,</span> <span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="c1">-- TODO</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>Some other examples:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="c1">-- `@linux`</span>
<span class="c1">-- `@linux|x86_64`</span>
<span class="c1">-- `@macosx,linux`</span>
<span class="c1">-- `android@macosx, linux`</span>
<span class="c1">-- `android|armv7-a@macosx,linux`</span>
<span class="c1">-- `android|armv7-a@macosx,linux|x86_64`</span>
<span class="c1">-- `android|armv7-a@linux|x86_64`</span>
</code></pre>
</div>

<h5 id="compilation-tools">Compilation Tools</h5>

<p>We have built-in scripts for installing common build tools for convenient build support for different source code-dependent build toolchains, such as autoconf, cmake, meson, etc.</p>

<h6 id="xmake">xmake</h6>

<p>If it is a xmake-based dependency package, then the integration is very simple, xmake has very good built-in integration support, you can directly support it for cross-platform compilation, generally only need to:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_install</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="n">import</span><span class="p">(</span><span class="s2">"package.tools.xmake"</span><span class="p">).</span><span class="n">install</span><span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>If you want to pass some unique build configuration parameters:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_install</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="n">import</span><span class="p">(</span><span class="s2">"package.tools.xmake"</span><span class="p">).</span><span class="n">install</span><span class="p">(</span><span class="n">package</span><span class="p">,</span> <span class="p">{</span><span class="s2">"--xxx=y"</span><span class="p">})</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<h6 id="cmake">cmake</h6>

<p>If it is a cmake-based package, the integration is also very short-answered. Usually you only need to set some configuration parameters, but you need to add the cmake dependency first:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_deps</span><span class="p">(</span><span class="s2">"cmake"</span><span class="p">)</span>
<span class="n">on_install</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="n">import</span><span class="p">(</span><span class="s2">"package.tools.cmake"</span><span class="p">).</span><span class="n">install</span><span class="p">(</span><span class="n">package</span><span class="p">,</span> <span class="p">{</span><span class="s2">"-Dxxx=ON"</span><span class="p">})</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<h6 id="autoconf">autoconf</h6>

<p>If it is based on autoconf package, the integration method is similar to cmake, but the configuration parameters are different. However, under normal circumstances, the Unix system has built-in autoconf series tools, so it is fine without any dependencies.</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_install</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="n">import</span><span class="p">(</span><span class="s2">"package.tools.autoconf"</span><span class="p">).</span><span class="n">install</span><span class="p">(</span><span class="n">package</span><span class="p">,</span> <span class="p">{</span><span class="s2">"--enable-shared=no"</span><span class="p">})</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>However, some source packages may not be fully satisfied with the system’s built-in autoconf, so you can add autoconf family dependencies and build them:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_deps</span><span class="p">(</span><span class="s2">"autoconf"</span><span class="p">,</span> <span class="s2">"automake"</span><span class="p">,</span> <span class="s2">"libtool"</span><span class="p">,</span> <span class="s2">"pkg-config"</span><span class="p">)</span>
<span class="n">on_install</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="n">import</span><span class="p">(</span><span class="s2">"package.tools.autoconf"</span><span class="p">).</span><span class="n">install</span><span class="p">(</span><span class="n">package</span><span class="p">,</span> <span class="p">{</span><span class="s2">"--enable-shared=no"</span><span class="p">})</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<h6 id="meson">meson</h6>

<p>If it is meson, you need to add ninja’s dependencies to perform the build.</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_deps</span><span class="p">(</span><span class="s2">"meson"</span><span class="p">,</span> <span class="s2">"ninja"</span><span class="p">)</span>
<span class="n">on_install</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="n">import</span><span class="p">(</span><span class="s2">"package.tools.meson"</span><span class="p">).</span><span class="n">install</span><span class="p">(</span><span class="n">package</span><span class="p">,</span> <span class="p">{</span><span class="s2">"-Dxxx=ON"</span><span class="p">})</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="on_test">on_test</h4>

<p>After installation, you need to set the corresponding test script, perform some tests to ensure the reliability of the installation package, if the test does not pass, the entire installation package will be revoked.</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_test</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="nb">assert</span><span class="p">(</span><span class="n">package</span><span class="p">:</span><span class="n">has_cfuncs</span><span class="p">(</span><span class="s2">"inflate"</span><span class="p">,</span> <span class="p">{</span><span class="n">includes</span> <span class="o">=</span> <span class="s2">"zlib.h"</span><span class="p">}))</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>The above script calls the built-in <code class="highlighter-rouge">has_cfuncs</code> interface to detect whether the zlib.h header file exists in the installed package, and whether the interface function <code class="highlighter-rouge">inflate</code> exists in the library and header files.</p>

<p>Xmake will try to compile the link for testing, <code class="highlighter-rouge">has_cfuncs</code> for detecting c functions, and <code class="highlighter-rouge">has_cxxfuncs</code> for detecting c++ library functions.</p>

<p>And include multiple header files in include, for example: <code class="highlighter-rouge">includes = {"xxx.h", "yyy.h"}</code></p>

<p>We can also pass some of our own compilation parameters into the detection, for example:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_test</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="nb">assert</span><span class="p">(</span><span class="n">package</span><span class="p">:</span><span class="n">has_cxxfuncs</span><span class="p">(</span><span class="s2">"func1"</span><span class="p">,</span> <span class="p">{</span><span class="n">includes</span> <span class="o">=</span> <span class="s2">"xxx.h"</span><span class="p">,</span> <span class="n">configs</span> <span class="o">=</span> <span class="p">{</span><span class="n">defines</span> <span class="o">=</span> <span class="s2">"c++14"</span><span class="p">,</span> <span class="n">cxflags</span> <span class="o">=</span> <span class="s2">"-Dxxx"</span><span class="p">}}))</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>We can also detect a code snippet with <code class="highlighter-rouge">check_csnippets</code> and <code class="highlighter-rouge">check_cxxsnippets</code>:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_test</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
    <span class="nb">assert</span><span class="p">(</span><span class="n">package</span><span class="p">:</span><span class="n">check_cxxsnippets</span><span class="p">({</span><span class="n">test</span> <span class="o">=</span> <span class="s">[[
        #include &lt;boost/algorithm/string.hpp&gt;
        #include &lt;string&gt;
        #include &lt;vector&gt;
        #include &lt;assert.h&gt;
        using namespace boost::algorithm;
        using namespace std;
        static void test() {
            string str("a,b");
            vector&lt;string&gt; strVec;
            split(strVec, str, is_any_of(","));
            assert(strVec.size()==2);
            assert(strVec[0]=="a");
            assert(strVec[1]=="b");
        }
    ]]</span><span class="p">},</span> <span class="p">{</span><span class="n">configs</span> <span class="o">=</span> <span class="p">{</span><span class="n">languages</span> <span class="o">=</span> <span class="s2">"c++14"</span><span class="p">}}))</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>if it is an executable package, it can also be detected by trying to run:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_test</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="n">os</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="s2">"xxx --help"</span><span class="p">)</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>if the run fails, the test will not pass.</p>

<h3 id="extended-configuration-parameters">Extended configuration parameters</h3>

<p>See: <a href="https://xmake.io/#/package/remote_package?id=add_configs">add_configs</a> for details.</p>

<h3 id="built-in-configuration-parameters">Built-in configuration parameters</h3>

<p>In addition to setting some extended configuration parameters via <a href="https://xmake.io/#/package/remote_package?id=add_configs">add_configs</a>, xmake also provides some built-in configuration parameters that can be used.</p>

<h4 id="enable-debug-package">Enable debug package</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"xxx"</span><span class="p">,</span> <span class="p">{</span><span class="n">debug</span> <span class="o">=</span> <span class="kc">true</span><span class="p">})</span>
</code></pre>
</div>

<p>There must be relevant processing in the package description to support:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_install</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="n">Local</span> <span class="n">configs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="err">    </span><span class="k">if</span> <span class="n">package</span><span class="p">:</span><span class="n">debug</span><span class="p">()</span> <span class="k">then</span>
<span class="err">        </span><span class="n">Table</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">configs</span><span class="p">,</span> <span class="s2">"--enable-debug"</span><span class="p">)</span>
<span class="err">    </span><span class="k">end</span>
<span class="err">    </span><span class="n">import</span><span class="p">(</span><span class="s2">"package.tools.autoconf"</span><span class="p">).</span><span class="n">install</span><span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="setting-up-the-msvc-runtime-library">Setting up the msvc runtime library</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"xxx"</span><span class="p">,</span> <span class="p">{</span><span class="n">configs</span> <span class="o">=</span> <span class="p">{</span><span class="n">vs_runtime</span> <span class="o">=</span> <span class="s2">"MT"</span><span class="p">}})</span>
</code></pre>
</div>

<p>Normally, packages installed by built-in tool scripts such as <code class="highlighter-rouge">import("package.tools.autoconf").install</code> are automatically processed internally by vs_runtime.</p>

<p>But if it is a special source package, the build rules are special, then you need to handle it yourself:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">on_install</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="n">io</span><span class="p">.</span><span class="n">gsub</span><span class="p">(</span><span class="s2">"build/Makefile.win32.common"</span><span class="p">,</span> <span class="s2">"%-MD"</span><span class="p">,</span> <span class="s2">"-"</span> <span class="o">..</span> <span class="n">package</span><span class="p">:</span><span class="n">config</span><span class="p">(</span><span class="s2">"vs_runtime"</span><span class="p">))</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<h3 id="adding-environment-variables">Adding environment variables</h3>

<p>For some libraries, there are also executable tools. if you need to use these tools in the integration package, you can also set the corresponding PATH environment variable:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">package</span><span class="p">(</span><span class="s2">"luajit"</span><span class="p">)</span>
<span class="err">    </span><span class="n">on_load</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">        </span><span class="k">if</span> <span class="n">is_plat</span><span class="p">(</span><span class="s2">"windows"</span><span class="p">)</span> <span class="k">then</span>
<span class="err">            </span><span class="n">Package</span><span class="p">:</span><span class="n">addenv</span><span class="p">(</span><span class="s2">"PATH"</span><span class="p">,</span> <span class="s2">"lib"</span><span class="p">)</span>
<span class="err">        </span><span class="k">end</span>
<span class="err">        </span><span class="n">Package</span><span class="p">:</span><span class="n">addenv</span><span class="p">(</span><span class="s2">"PATH"</span><span class="p">,</span> <span class="s2">"bin"</span><span class="p">)</span>
<span class="err">    </span><span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>In the project project, the corresponding environment variables will only take effect after the corresponding package is integrated by <code class="highlighter-rouge">add_packages</code>.</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"luajit"</span><span class="p">)</span>
<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
<span class="err">    </span><span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
<span class="err">    </span><span class="n">add_packages</span><span class="p">(</span><span class="s2">"luajit"</span><span class="p">)</span>
<span class="err">    </span><span class="n">after_run</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">        </span><span class="n">os</span><span class="p">.</span><span class="n">exec</span><span class="p">(</span><span class="s2">"luajit --version"</span><span class="p">)</span>
<span class="err">    </span><span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<h3 id="installing-binary-packages">Installing binary packages</h3>

<p>Xmake also supports direct reference to the binary version package, which is used directly for installation, for example:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="k">if</span> <span class="n">is_plat</span><span class="p">(</span><span class="s2">"windows"</span><span class="p">)</span> <span class="k">then</span>
<span class="err">    </span><span class="n">set_urls</span><span class="p">(</span><span class="s2">"https://www.libsdl.org/release/SDL2-devel-$(version)-VC.zip"</span><span class="p">)</span>
<span class="err">    </span><span class="n">add_versions</span><span class="p">(</span><span class="s2">"2.0.8"</span><span class="p">,</span> <span class="s2">"68505e1f7c16d8538e116405411205355a029dcf2df738dbbc768b2fe95d20fd"</span><span class="p">)</span>
<span class="k">end</span>

<span class="n">on_install</span><span class="p">(</span><span class="s2">"windows"</span><span class="p">,</span> <span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">)</span>
<span class="err">    </span><span class="n">os</span><span class="p">.</span><span class="n">cp</span><span class="p">(</span><span class="s2">"include"</span><span class="p">,</span> <span class="n">package</span><span class="p">:</span><span class="n">installdir</span><span class="p">())</span>
<span class="err">    </span><span class="n">os</span><span class="p">.</span><span class="n">cp</span><span class="p">(</span><span class="s2">"lib/$(arch)/*.lib"</span><span class="p">,</span> <span class="n">package</span><span class="p">:</span><span class="n">installdir</span><span class="p">(</span><span class="s2">"lib"</span><span class="p">))</span>
<span class="err">    </span><span class="n">os</span><span class="p">.</span><span class="n">cp</span><span class="p">(</span><span class="s2">"lib/$(arch)/*.dll"</span><span class="p">,</span> <span class="n">package</span><span class="p">:</span><span class="n">installdir</span><span class="p">(</span><span class="s2">"lib"</span><span class="p">))</span>
<span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<h3 id="local-test">Local test</h3>

<p>If you have added and created a new package in the local xmake-repo repository, you can run the test locally and pass it. If the test passes, you can submit the pr to the official repository and request the merge.</p>

<p>We can execute the following script to test the specified package:</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="nb">cd </span>xmake-repo
xmake l scripts/test.lua -v -D zlib
</code></pre>
</div>

<p>The above command will force the download and installation of the zlib package to test whether the entire installation process is ok, plus <code class="highlighter-rouge">-v -D</code> is to see the complete detailed log information and error information, which is convenient for debugging analysis.</p>

<p>If the network environment is not good, do not want to re-download all dependencies every time, you can add the <code class="highlighter-rouge">--shallow</code> parameter to execute, this parameter tells the script, just re-decompress the local cached zlib source package, re-execute the installation command, but Will not download various dependencies.</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="nb">cd </span>xmake-repo
xmake l scripts/test.lua -v -D --shallow zlib
</code></pre>
</div>

<p>If we want to test the package rules of other platforms, such as: android, iphoneos and other platforms, you can specify by <code class="highlighter-rouge">-p/--plat</code> or <code class="highlighter-rouge">-a/--arch</code>.</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="nb">cd </span>xmake-repo
xmake l scripts/test.lua -v -D --shallow -p iphoneos -a arm64 zlib
xmake l scripts/test.lua -v -D --shallow -p android --ndk<span class="o">=</span>/xxxx zlib
</code></pre>
</div>

<h2 id="submit-package-to-the-official-repository">Submit package to the official repository</h2>

<p>If you need a package that is not supported by the current official repository, you can commit it to the official repository after local tuning: <a href="https://github.com/xmake-io/xmake-repo">xmake-repo</a></p>

<p>For detailed contribution descriptions, see: <a href="https://github.com/xmake-io/xmake-repo/blob/master/CONTRIBUTING.md">CONTRIBUTING.md</a></p>

<p>For how to make your own package, you can look at the above: <a href="https://xmake.io/#/package/remote_package?id=adding-packages-to-the-official-repository">Adding packages to the official repository</a>.</p>

        </article>
        <hr>

        <!-- baidu ads -->
        

        
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
                    
                    <h2 id="chinese">中文</h2>
                    <ul>
                    
                    <li class="relatedPost">
                        <a href="/cn/2019/08/09/xmake-upload-package/">制作和上传C/C++包到xmake的官方仓库
                        
                        </a>
                    </li>
                    
                    
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
        
            </ul>
        

        
        
            
            
            
                
                    
                        
                        <h2 id="similar_posts">Similar Posts</h2>
                        <ul>
                        
                        <li class="relatedPost">
                            <a href="/2021/12/17/xmake-update-v2.6.2/">Xmake v2.6.2 released, Support building Linux kernel driver module
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/2021/12/03/xmake-update-v2.6.1/">xmake v2.6.1 released, Switch to Lua5.4 runtime, Support Rust and C++ mixed compilation
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/2021/10/30/xmake-update-v2.5.9/">xmake v2.5.9 released, Improve C++20 Modules and support Nim, Keil MDK and Unity Build
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/2021/10/08/xmake-update-v2.5.8/">xmake v2.5.8 is released, Support Pascal/Swig program and Lua53 runtime
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/2021/08/29/xmake-update-v2.5.7/">xmake v2.5.7 released, Use lockfile to freeze package dependencies and Vala/Metal language support
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
        
            </ul>
        

        <div class="post-recent">
    <div class="pre">

        

        

        
        
        

        

        

        
        
        <p><strong>Prev Post</strong> <a href="/2019/06/17/xmake-update-v2.2.7/">xmake v2.2.7 released, Improve to build Cuda project</a></p>
        
    </div>

    <div class="nex">

        

        

        
        
        

        

        

        
        
        <p><strong>Next Post</strong> <a href="/2019/08/22/xmake-update-v2.2.8/">xmake v2.2.8 released, New vs project generator</a></p>
        
    </div>
</div>


        <h2 id="comments">Comments</h2>
        






<div id="gitalk-container"></div>
<link rel="stylesheet" href="/css/gitalk.css">
<script src="/js/gitalk.min.js"></script>

<script>
const gitalk = new Gitalk({
  clientID: '73946dc1d9e2276ad0da',
  clientSecret: '12a3cb94361ba3ebc6ecb68cf80d592bfaa8106d',
  repo: 'tboox.github.io',
  owner: 'waruqi',
  admin: ['waruqi'],
  id: location.pathname,      
  language: 'en',
  distractionFreeMode: false  
})

gitalk.render('gitalk-container')
</script>





    </div>
    <button class="anchor"><i class="fa fa-anchor"></i></button>
    <div class="right">
        <div class="wrap">


            <!-- codefund ads -->
            

            <!-- Content -->
            <div class="side content">
                <div>
                    Content
                </div>
                <ul id="content-side" class="content-ul">
                    <li><a href="#chinese">中文</a></li>
                    <li><a href="#similar_posts">Similar Posts</a></li>
                    <li><a href="#comments">Comments</a></li>
                </ul>
            </div>

            <!-- baidu ads -->
            

            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    Links
                </div>
                <ul class="content-ul">
                  <li><a href="http://github.com/waruqi/tbox">tbox</a></li>
                  <li><a href="http://www.xmake.io">xmake</a></li>
                  <li><a href="https://github.com/waruqi">github</a></li>
                </ul>
            </div> 

            <!-- google ads -->
            

            <!-- baidu ads -->
            

            <!-- chitika ads -->
            
        </div>
    </div>

    <!-- baidu ads -->
    
</div>
<script>
/**
 * target _blank
 */
(function() {
    var aTags = document.querySelectorAll('article a:not([id])')
    for (var i = 0; i < aTags.length; i++) {
        aTags[i].setAttribute('target', '_blank')
    }
}());
</script>
<script src="/js/pageContent.js " charset="utf-8"></script>



    <footer class="site-footer">
    <div class="wrapper">
        <p class="description">
             Copyright (c) 2016-2020 tboox.org 
        </p>
        <p class="contact">
            
            <a href="https://github.com/waruqi" title="GitHub"><i class="fa fa-github" aria-hidden="true"></i></a> 
             
            
            <a href="mailto:waruqi@gmail.com" title="email"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> 
            
            
            <a href="https://twitter.com/waruqi" title="Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a> 
            
            <a href="/feed.xml" title="feed"><i class="fa fa-feed" aria-hidden="true"></i></a> 
        </p>
        <p class="power">
            <span>
                Site powered by <a href="https://jekyllrb.com/">Jekyll</a> & <a href="https://github.com/Gaohaoyang">HyG</a> & <a href="https://pages.github.com/">Github Pages</a>.
            </span>
        </p>
    </div>
</footer>

    <div class="back-to-top">
    <a href="#top" class="scroll">
        <i class="fa fa-arrow-up" aria-hidden="true"></i>
    </a>
</div>

    <script src=" /js/main.js " charset="utf-8"></script>
    <script src=" /js/scroll.min.js " charset="utf-8"></script>
  </body>

</html>
